package com.hisan.freeride.home.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.github.library.BaseQuickAdapter;
import com.github.library.listener.OnItemClickListener;

import com.hisan.freeride.R;
import com.hisan.freeride.common.base.AppConfig;
import com.hisan.freeride.common.base.BaseActivity;
import com.hisan.freeride.common.base.BaseAppLication;
import com.hisan.freeride.common.callback.DialogCallback;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.common.utils.utils.TokenUtils;
import com.hisan.freeride.common.view.MyGridLayoutManager;
import com.hisan.freeride.common.view.ViewRefreshHeader;
import com.hisan.freeride.databinding.IntegralmallBinding;

import com.hisan.freeride.home.model.Mall;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;
import com.lzy.okgo.OkGo;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 创建时间 : 2017/6/6
 * 创建人：yangyingqi
 * 公司：嘉善和盛网络有限公司
 * 备注：积分商城页面
 */
public class IntegralMallActivity extends BaseActivity<IntegralmallBinding> {
    private int page=1;
//    private MallAdapter adapter;
//    TestNormalAdapter testNormalAdapte;
//    private List<Mall.AdvertBean> advertBeans;

    @Override
    protected int getLayoutId() {
        return R.layout.integralmall;
    }

    @Override
    protected void initView() {
        mBinding.setStateModel(mStateModel);
        //adapter=new MallAdapter(new ArrayList<>(0));
//        mBinding.rv.setLayoutManager(new MyGridLayoutManager(this,2));
//        mBinding.rv.setAdapter(adapter);
//        if (mBinding.refreshLayout!= null) {
//            // 刷新状态的回调
//            mBinding.refreshLayout.setRefreshListener(() -> {
//                mBinding.refreshLayout.refreshComplete();
//                loadData(true);
//            });
//        }
//        ViewRefreshHeader header  = new ViewRefreshHeader(this);
//        mBinding.refreshLayout.setRefreshHeader(header);
    }

    @Override
    protected void initEvent() {
//        mBinding.rv.addOnItemTouchListener(new OnItemClickListener() {
//            @Override
//            public void onSimpleItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
//                Mall.GoodsBean goods= (Mall.GoodsBean) baseQuickAdapter.getItem(i);
//                Bundle bundle=new Bundle();
//                bundle.putLong("id",goods.getId());
//                startActivityForResult(MallDetailsActivity.class,99,bundle,true);
//            }
//        });
//        mBinding.loveMoney.setOnClickListener(v -> startActivityForResult(LovePriceActivity.class,98,null,true));
//        mBinding.duihuan.setOnClickListener(v -> startActivityForResult(ExchangeActivity.class,0,null,true));
//        mBinding.pager.setOnItemClickListener(position -> {
//            if (!CollectionUtils.isNullOrEmpty(advertBeans)) {
//                if (CollectionUtils.checkURL(advertBeans.get(position).getUrl()))
//                    RotationActivity.skip(IntegralMallActivity.this, advertBeans.get(position).getUrl());
//            }
//        });
    }

    @Override
    protected void loadData(boolean isRefresh) {
//        OkGo.<Mall>get(AppConfig.glist)
//                .tag(this)
//                .params("city_id",BaseAppLication.getInstance().getCityid())
//                .params("pageNumber",page)
//                .params("pageSize",20)
//                .execute( new DialogCallback<Mall>(this){
//                    @Override
//                    public void onSuccess(com.lzy.okgo.model.Response<Mall> response) {
//                        super.onSuccess(response);
////                        if (!CollectionUtils.isNullOrEmpty(response.body().getCoin())){
////                            mBinding.lovePirce.setText(response.body().getCoin()+"");
////                        }
//                        if (!CollectionUtils.isNullOrEmpty(response.body().getAdvert())){
//                            advertBeans=new ArrayList<Mall.AdvertBean>();
//                            advertBeans=response.body().getAdvert();
//                            testNormalAdapte=new TestNormalAdapter();
//                            mBinding.pager.setAdapter(testNormalAdapte);
//                            mBinding.pager.setHintView(new ColorPointHintView(getApplication(), getResources().getColor(R.color.home_titel),getResources().getColor(R.color.colorLighterGray)));
//                        }
//
//                        if(!CollectionUtils.isNullOrEmpty(response.body())){
//                            showData();
//                            adapter.setNewData(response.body().getGoods());
//                        }else{
//                            noData();
//                        }
//                    }
//
//                    @Override
//                    public void onError(com.lzy.okgo.model.Response<Mall> response) {
//                        super.onError(response);
//                        showErrorView(response.code());
//                    }
//                });
    }
//
//
//    //轮播适配器
//    private class TestNormalAdapter extends StaticPagerAdapter {
//        @Override
//        public View getView(ViewGroup container, int position) {
//            ImageView view = new ImageView(container.getContext());
//            if (!CollectionUtils.isNullOrEmpty(advertBeans.get(position).getThumbnail())){
//                Glide.with(IntegralMallActivity.this)
//                        .load(advertBeans.get(position).getThumbnail())
//                        .placeholder(R.mipmap.lunbo)//设置占位图
//                        .error(R.mipmap.lunbo)
//                        .into(view);
//                view.setScaleType(ImageView.ScaleType.CENTER_CROP);
//                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//            }
//            return view;
//        }
//        @Override
//        public int getCount() {
//            return advertBeans.size();
//        }
//    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
           loadData(true);
    }
}
